<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Leaflet debug page - Rectangle</title>
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
		<link rel="stylesheet" href="../../dist/leaflet.css" />
		<link rel="stylesheet" href="../css/screen.css" />
		<script type="importmap">
			{
				"imports": {
					"leaflet": "../../dist/leaflet-src.esm.js"
				}
			}
		</script>
	</head>
	<body>
		<div id="map"></div>
		<button id="resetBounds" type="button">
			Set blue rectangle bounds as current map extent.
		</button>
		<script type="module">
			import {TileLayer, LatLngBounds, LatLng, Rectangle, Map} from 'leaflet';

			const osm = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 18});
			const bounds = new LatLngBounds(new LatLng(54.559322, -5.767822), new LatLng(56.1210604, -3.021240));
			const bounds2 = new LatLngBounds(new LatLng(56.2124322195806, -3.427734375), new LatLng(56.307776937156945, -3.2560729980468746));

			const rectangle = new Rectangle(bounds);
			const styledRectangle = new Rectangle(bounds2, {
				fillColor: '#ff7800',
				color: '#000000',
				opacity: 1,
				weight: 2
			});

			rectangle.on('click', () => {
				alert('you clicked a rectangle.');
			});

			rectangle.bindPopup('I\'m a rectangle!');

			const map = new Map('map', {
				center: bounds.getCenter(),
				zoom: 7,
				layers: [osm]
			});

			map.addLayer(rectangle).addLayer(styledRectangle);

			const resetBoundsBtn = document.getElementById('resetBounds');

			resetBoundsBtn.addEventListener('click', resetBounds);

			function resetBounds() {
				rectangle.setBounds(map.getBounds());
			}
		</script>
	</body>
</html>
